package org.zky.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.zky.dao.IContactDao;
import org.zky.entities.Contact;

/**
* @ClassName: IContactDaoImpl
* @Description: dao，自动注入不需要写getter和setter方法。
* @author zhaokunyang@utry.cn
* @date 2015年10月4日 下午6:56:13
* 
*/

@Repository
public class IContactDaoImpl  implements IContactDao {
	

	@Autowired
	public SessionFactory sessionFactory;
	@Autowired
	public HibernateTemplate hibernateTemplate;
	
	
	
	public Contact findContact(Contact contact) throws SQLException {
		
		List<Contact> list = hibernateTemplate.findByExample(contact);
		
		return contact;
	}

	public Contact findContactById(int id) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public void addContact(Contact contact) throws SQLException {
		hibernateTemplate.save(contact);
		
	}

	public void delContact(Contact contact) throws SQLException {
		List<Contact> list = findContacts(contact);
		for(Contact c:list){
			hibernateTemplate.delete(c);
		}
		
	}

	public List<Contact> findContacts(Contact contact) throws SQLException {
		List<Contact> list = hibernateTemplate.findByExample(contact);

		return list;
	}

}
